<!--
 * @Author: ssj
 * @Date: 2021-12-08 09:25:16
 * @LastEditors: zss
 * @LastEditTime: 2024-11-23 11:16:19
 * @Description: 
-->
<template>
  <i-col
    :lg="16"
    :md="16"
    :style="{
      flex: '0 0 calc(' + 25 * ffieldwidth + '%' + ' - ' + 10 + 'px)',
      height: (fheight || 300) + 'px'
    }"
  >
    <div class="home-page-box">
      <div class="home-page-header clear">
        <div class="home-page-header-left">
          <!-- {{ $srv.getI18nByPath('menu.commonnavigation') }} -->
          <span>仿真排程</span>
        </div>
      </div>

      <div class="home-page-body">
        <div class="text">
          <p>默认排程时间：{{ getShowTime(scheduleTime.default) }}</p>
          <p>
            智能排产时间：{{ getShowTime(scheduleTime.intelligent) }},节约{{
              getShowTime(scheduleTime.saveTime)
            }}时间
          </p>
        </div>
      </div>
    </div>
  </i-col>
</template>
<script lang="ts">
import { Tsrv, T_srv, ifs, ts, vue } from '@/services';

@T_srv.comp
export default class homeSTCard extends vue {
  @T_srv.inject() addTabFunc;

  @T_srv.prop({})
  ffieldwidth: number;

  @T_srv.prop({})
  fheight: number;

  private scheduleTime = {
    default: 0,
    intelligent: 0,
    saveTime: 0
  };

  get getShowTime() {
    return (time: number) => {
      const seconds = Math.floor(time / 1000);
      const hours = seconds > 3600 ? Math.floor(seconds / 3600) : 0;
      const minutes = Math.floor((seconds % 3600) / 60);
      const secondsLeft = seconds % 60;

      return `${hours
        .toString()
        .padStart(2, '0')}时${minutes
        .toString()
        .padStart(2, '0')}分${secondsLeft.toString().padStart(2, '0')}秒`;
    };
  }

  mounted() {
    this.init();
    this.$bus.$on('MY_SCHEDULETIME', (id: any) => {
      const filter = {
        // eslint-disable-next-line camelcase
        production_line: id
      };
      this.init(filter);
    });
  }

  private async init(filter = {}) {
    const [b, res, rows, msg] = await this.doLoadData(
      'simu_sche_time',
      'simu_sche_time',
      filter
    );
    if (!b) {
      this.$msg(msg ?? res.msg);
    } else {
      rows.forEach(item => {
        this.scheduleTime.default += item['default_sche_time'];
        this.scheduleTime.intelligent += item['Intel_sche_time'];
      });
      this.scheduleTime.saveTime =
        this.scheduleTime.default - this.scheduleTime.intelligent;
    }
  }

  public doLoadData(funName: string, tableName: string, filter: object = {}) {
    const gpd = new ts.T_getPartDataArg();
    gpd.setFilter(filter);
    gpd.setFunName(tableName);
    gpd.setTableName(tableName);
    gpd.setDbType(Tsrv.globalVar.dbType.MYSQL);
    gpd.setLang(this.$i18n.locale);
    gpd.setPage(1, 99999);
    gpd.setRule({} as ifs.I_rule);

    return Tsrv.getData(gpd);
  }
}
</script>
<style lang="scss" scoped>
.text {
  padding-left: 10px;
}
</style>
